<?php 
class Accountmodel extends CI_Model {
	
	

	function __construct()
	{
		// Call the Model constructor
		parent::__construct();
	}
	
	function get_user_info($value)
	{
		$where = "1";
		if(is_numeric($value)){
			$where = "acct = ".$value;
		}else{
			$where = "login = '$value'";
		}
		$query = $this->db->query("SELECT acct, login, lastlogin, lastip, flags, email
								FROM accounts
								WHERE $where
							");
		return $query->result();
	}
	
	function login_update($id){
		$this->db->query("UPDATE accounts
								SET lastlogin = NOW(),
								lastip = '".$_SERVER["REMOTE_ADDR"]."'
								WHERE acct = $id
							");
	}
	
	function login(){
		$query = $this->db->query("SELECT acct, login, lastlogin, lastip, flags, email
								FROM accounts
								WHERE login = '".$this->db->escape_str($this->input->post('username'))."'
								AND password = '".$this->db->escape_str($this->input->post('password'))."'
							");
		return $query->result();
	}
	
   function insert_account()
   {
       $this->login   = $this->input->post('username', TRUE);; // please read the below note
       $this->password = $this->input->post('password', TRUE);
       $this->email    = $this->input->post('email', TRUE);;

       $this->db->insert('accounts', $this);
   }

	function update_entry()
	{
	}

}
?>